﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Game.Graphics
{
    class TextureMap
    {
        private Dictionary<string, Texture2D> StringToTextureMap;
        private List<string> IntToStringMap;

        public TextureMap()
        {
            StringToTextureMap = new Dictionary<string, Texture2D>();
            IntToStringMap = new List<string>();
        }

        public int LoadTexture(string textureFilename)
        {
            DataLoading.ContentLoader loader = DataLoading.ContentLoader.Instance;
            if(StringToTextureMap.ContainsKey(textureFilename))
            {
                return IntToStringMap.IndexOf(textureFilename);
            }
            else
            {
                
                IntToStringMap.Add(textureFilename);
                Texture2D texture = loader.LoadTexture(textureFilename);
                StringToTextureMap.Add(textureFilename, texture);
                return IntToStringMap.Count - 1;
            }
        }

        public Texture2D GetTexture(int TextureID)
        {
            if ((TextureID >= IntToStringMap.Count) || (TextureID < 0))
            {
                return null;
            }

            string textureName = IntToStringMap[TextureID];
            return StringToTextureMap[textureName];
        }
    }
}
